#import "AppController.h"
#import "YCAlert.h"

@implementation AppController

- (IBAction)showYCAlert:(id)sender
{
    NSButton *button;
    
    alert = [[YCAlert alloc] init];
    [alert setTitle:@"My Title"];
    [alert setMessageText:@"My Message"];
    [alert setInformativeText:@"Build a man a fire, and he'll be warm for a day. Set a man on fire, \
and he'll be warm for the rest of his life.\r\r--Terry Pratchett"];
    [alert addPrimaryButtonWithTitle:@"OK"];
    button = [alert addAlternateButtonWithTitle:@"Cancel"];
    [button setKeyEquivalent:@"\e"];
    button = [alert addOtherButtonWithTitle:@"Longer Name"];
    [button setKeyEquivalent:@"d"];
    [button setKeyEquivalentModifierMask:NSCommandKeyMask];
    [alert beginModelessAlertWithDelegate:self selector:@selector( alertDidEnd:returnCode:contextInfo: )
        contextInfo:nil];
}

- (void)alertDidEnd:(YCAlert *)anAlert returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
    NSLog( @"%s %d", _cmd, returnCode );
    [anAlert release]; anAlert = nil;
}

- (IBAction)showNSAlert:(id)sender
{
    realAlert = [[NSAlert alloc] init];
    [realAlert setAlertStyle:NSWarningAlertStyle];
    [realAlert setMessageText:@"Alert"];
    [realAlert setInformativeText:@"Informative"];
    [realAlert addButtonWithTitle:@"OK"];
    [realAlert addButtonWithTitle:@"Cancel"];
    [realAlert addButtonWithTitle:@"Don't Save"];
    [realAlert beginSheetModalForWindow:[sender window] modalDelegate:self
        didEndSelector:@selector( realAlertDidEnd:returnCode:contextInfo: ) contextInfo:nil];
}

- (void)realAlertDidEnd:(NSAlert *)anAlert returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
    NSLog( @"%s %d", _cmd, returnCode );
    [anAlert release]; anAlert = nil;
}

@end
